package com.im.config.swagger2;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 接口文档配置类
 * 原有 Swagger2Config 通过 springfox 注解实现，现在替换为 Jakarta 版 Knife4j + springdoc-openapi 方案
 */
@Configuration
@SpringBootConfiguration
@EnableKnife4j
@Slf4j
public class Swagger2Config {

    // 假设你已有一个配置属性类 Swagger2ConfigProperties，
    // 如果没有可直接硬编码或使用 @Value 注入属性
    @Bean
    public OpenAPI customOpenAPI(Swagger2ConfigProperties properties) {
        return new OpenAPI()
                .info(new Info()
                        .title(properties.getTitle())                   // 设置标题
                        .description(properties.getDescription())       // 设置描述
                        .termsOfService(properties.getTermsOfServiceUrl())// 设置服务条款 URL
                        .version(properties.getVersion())               // 设置版本
                        .contact(new Contact()                           // 设置联系信息
                                .name(properties.getContactName())
                                .url(properties.getContactUrl())
                                .email(properties.getContactEmail())))
                .components(new Components()
                        .addSecuritySchemes("Authorization", new SecurityScheme()
                                .type(SecurityScheme.Type.APIKEY)
                                .in(SecurityScheme.In.HEADER)
                                .name("Authorization")))
                .addSecurityItem(new SecurityRequirement().addList("Authorization"));
    }
}
